# coding:utf-8
# writingtime: 2022-6-30
# author: wanjun
# reference: Pythagorean Fuzzy Maclaurin Symmetric Mean Operators in Multiple Attribute Decision Making
# doi:  10.1002/int.21911
# examiner:

import os
import math as m
from itertools import combinations
from Utilities.AutoGetOperator.selectPackage import get_func

Operator_IVQ_ROFS=get_func(r'Operators/OperationOperators/OperatorIVQROF.py','Operator_IVQ_ROFS')


class MaclaurinSymmetricMeanA(Operator_IVQ_ROFS):
    def getResult(self):
        '''
        function: HamyMwan算子的基本公式
        :return:
        '''
        # 获得排列组合的结果
        length=len(self.data_list)
        self.ik = list(combinations([i + 1 for i in range(length)], self.x))
        # 计算组合的个数
        self.rank_numb = m.factorial(length) / (m.factorial(self.x) * (m.factorial(length - self.x)))

        ik1 = self.ik[0]
        s = self.data_list[ik1[0] - 1]
        for j in range(1, len(ik1)):
            s = self.multi(s, self.data_list[ik1[j] - 1])

        for i in range(1, len(self.ik)):
            s1 = self.data_list[self.ik[i][0] - 1]
            for j in range(1, len(self.ik[i])):
                s1 = self.multi(s1, self.data_list[self.ik[i][j] - 1])

            s = self.add(s, s1, self.q)
        s = self.kmulti(s, 1 / self.rank_numb, self.q)
        s = self.pow(s, 1 / self.x, self.q)

        return s

class MaclaurinSymmetricMeanGA(Operator_IVQ_ROFS):
    def getResult(self):
        '''
        function: HamyMwan算子的基本公式
        :return:
        '''
        # 获得排列组合的结果
        length=len(self.data_list)
        self.ik = list(combinations([i + 1 for i in range(length)], self.x))
        # 计算组合的个数
        self.rank_numb = m.factorial(length) / (m.factorial(self.x) * (m.factorial(length - self.x)))

        ik1 = self.ik[0]
        s = self.data_list[ik1[0] - 1]
        for j in range(1, len(ik1)):
            s = self.add(s, self.data_list[ik1[j] - 1])

        for i in range(1, len(self.ik)):
            s1 = self.data_list[self.ik[i][0] - 1]
            for j in range(1, len(self.ik[i])):
                s1 = self.add(s1, self.data_list[self.ik[i][j] - 1])

            s = self.multi(s, s1, self.q)
        s = self.pow(s, 1 / self.rank_numb, self.q)
        s = self.kmulti(s, 1 / self.x, self.q)

        return s

class MaclaurinSymmetricMeanWA(Operator_IVQ_ROFS):
    def getResult(self):
        '''
        function: HamyMwan算子的基本公式
        :return:
        '''
        # 获得排列组合的结果
        length=len(self.data_list)
        self.ik = list(combinations([i + 1 for i in range(length)], self.x))
        # 计算组合的个数
        self.rank_numb = m.factorial(length) / (m.factorial(self.x) * (m.factorial(length - self.x)))

        ik1 = self.ik[0]
        s = self.kmulti(self.data_list[ik1[0] - 1], self.weight_list[ik1[0] - 1])
        for j in range(1, len(ik1)):
            temp = self.kmulti(self.data_list[ik1[j] - 1], self.weight_list[ik1[j] - 1])
            s = self.multi(s, temp)

        for i in range(1, len(self.ik)):
            s1 = self.kmulti(self.data_list[self.ik[i][0] - 1], self.weight_list[self.ik[i][0] - 1])
            for j in range(1, len(self.ik[i])):
                temp = self.kmulti(self.data_list[self.ik[i][j] - 1], self.weight_list[self.ik[i][j] - 1])
                s1 = self.multi(s1, temp)
            s = self.add(s, s1, self.q)
        s = self.kmulti(s, 1 / self.rank_numb, self.q)
        s = self.pow(s, 1 / self.x, self.q)

        return s

class MaclaurinSymmetricMeanWGA(Operator_IVQ_ROFS):
    def getResult(self):
        '''
        function: HamyMwan算子的基本公式
        :return:
        '''
        # 获得排列组合的结果
        length=len(self.data_list)
        self.ik = list(combinations([i + 1 for i in range(length)], self.x))
        # 计算组合的个数
        self.rank_numb = m.factorial(length) / (m.factorial(self.x) * (m.factorial(length - self.x)))

        ik1 = self.ik[0]
        s = self.kmulti(self.data_list[ik1[0] - 1], self.weight_list[ik1[0] - 1])
        for j in range(1, len(ik1)):
            temp = self.kmulti(self.data_list[ik1[j] - 1], self.weight_list[ik1[j] - 1])
            s = self.add(s, temp)

        for i in range(1, len(self.ik)):
            s1 = self.kmulti(self.data_list[self.ik[i][0] - 1], self.weight_list[self.ik[i][0] - 1])
            for j in range(1, len(self.ik[i])):
                temp = self.kmulti(self.data_list[self.ik[i][j] - 1], self.weight_list[self.ik[i][j] - 1])
                s1 = self.add(s1, temp)
            s = self.multi(s, s1, self.q)
        s = self.pow(s, 1 / self.rank_numb, self.q)
        s = self.kmulti(s, 1 / self.x, self.q)

        return s

class MaclaurinSymmetricMeanOWA(Operator_IVQ_ROFS):
    def getResult(self):
        '''
        function: HamyMwan算子的基本公式
        :return:
        '''
        # 将 数据集备份，将类中数据集属性 替换为 排序后的数据集
        data_list = self.data_list
        self.data_list = self.sortdata()

        # 获得排列组合的结果
        length=len(self.data_list)
        self.ik = list(combinations([i + 1 for i in range(length)], self.x))
        # 计算组合的个数
        self.rank_numb = m.factorial(length) / (m.factorial(self.x) * (m.factorial(length - self.x)))

        ik1 = self.ik[0]
        s = self.kmulti(self.data_list[ik1[0] - 1], self.weight_list[ik1[0] - 1])
        for j in range(1, len(ik1)):
            temp = self.kmulti(self.data_list[ik1[j] - 1], self.weight_list[ik1[j] - 1])
            s = self.multi(s, temp)

        for i in range(1, len(self.ik)):
            s1 = self.kmulti(self.data_list[self.ik[i][0] - 1], self.weight_list[self.ik[i][0] - 1])
            for j in range(1, len(self.ik[i])):
                temp = self.kmulti(self.data_list[self.ik[i][j] - 1], self.weight_list[self.ik[i][j] - 1])
                s1 = self.multi(s1, temp)
            s = self.add(s, s1, self.q)
        s = self.kmulti(s, 1 / self.rank_numb, self.q)
        s = self.pow(s, 1 / self.x, self.q)

        # 还原数据集
        self.data_list = data_list
        return s

if __name__=="__main__":
    list1 = [([0.85, 0.95], [0.1, 0.2]), ([0.8, 0.9], [0.1, 0.2]), ([0.85, 0.95], [0.1, 0.2]), ([0.7, 0.8], [0.2, 0.3]),
             ([0.4, 0.5], [0.5, 0.6])]
    a = MaclaurinSymmetricMeanWGA(list1, [0.2, 0.2, 0.2, 0.2, 0.2], 3)
    print(a.getResult())
